import React, { useState, useEffect } from 'react';
import Store from "./../store/store"
import * as actions from './../store/actions'
const ProductViews = () => {
  const [number, setNumber] = useState(Store.getState().count)
  useEffect(() => {
    let unSubscribe = Store.subscribe(() => {
      setNumber(Store.getState().count)
    });

    return () => {
      unSubscribe()
    }
  })
  return (
    <div>
      <h1>ProductViews</h1>
      <h3>count: {number} </h3>
      <button type='button' onClick={
        () => {
          Store.dispatch(actions.addNum(100))
        }
      }>+++++</button>

      <button type='button' onClick={() => {
        Store.dispatch(actions.jian(100))
      }}> -----</button>
    </div>
  );
}

export default ProductViews;
